/********************************************************************************
* Description: abstract network service
* Author: hsqiang
* Create Date: 2023-06-21
********************************************************************************/
#ifndef NET_SERVICE_HPP_
#define NET_SERVICE_HPP_

#include "event_loop.hpp"
#include "socket.hpp"
#include "net_event_callback.hpp"
#include "noncopyable.hpp"
#include <memory>
#include <functional>

namespace event_framework
{
    class NetService : Noncopyable
    {
    public:
        virtual bool Init() { return true; }
        virtual bool Fini() { return true; }
        void SetEventCallback(EventCallback&& callback)
        {
            eventCallback = std::move(callback);
        }
        void SetReadableCallback(ReadableCallback&& cb)
        {
            eventCallback.readableCallback = std::move(cb);
        }
        void SetWriteableCallback(WriteableCallback&& cb)
        {
            eventCallback.writeableCallback = std::move(cb);
        }
        void SetClosedCallback(ClosedCallback&& cb)
        {
            eventCallback.closedCallback = std::move(cb);
        }
        void SetExceptionCallback(ExceptionCallback&& cb)
        {
            eventCallback.exceptionCallback = std::move(cb);
        }
    protected:
        explicit NetService(EventLoop& loop_, const EndPoint& ep) : loop(loop_), socket(ep) {}
        virtual ~NetService() = default;
        EventLoop& loop;
        Socket socket;
        EventCallback eventCallback;
    private:
    };
    using NetServicePtr = std::unique_ptr<NetService>;
}

#endif